using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using System.ComponentModel;
using System.Web.UI;
using System.Xml;

namespace TanashCMS.Business
{
    [DataObject(true)]
    public class Navigation : CMSDataObject
    {
        private int mTargetID, mParentID;
        private CMSObjectType mTargetType;
        private string mNavigateURL;
        private TanashWebsite mWebsite=null;
        private List<Navigation> mChildren = new List<Navigation>();
        private bool mIsStatic, mIsDefault;

        public virtual int TargetID { get { return mTargetID; } set { mTargetID = value; } }
        public virtual int ParentID { get { return mParentID; } set { mParentID = value; } }
        public virtual CMSObjectType TargetType { get { return mTargetType; } set { mTargetType = value; } }
        public virtual string NavigateURL { get { return mNavigateURL; } set { mNavigateURL = value; } }
        public virtual bool IsStatic { get { return mIsStatic; } set { mIsStatic = value; } }
        
        public bool IsDefault { get { return mIsDefault; } set { mIsDefault = value; } }
	
        
        public virtual TanashWebsite Website { get { return mWebsite; } set { mWebsite = value  ; } }
        public virtual List<Navigation> Children { get { return mChildren; } set { mChildren = value; } } 


        public static Navigation findByTitle(int WebsiteID, int ParentID, string Title)
        {
            ISession session = Configuration.GetCurrentSession();
            Navigation nav = (Navigation)session.CreateQuery("select n from Navigation n where n.Title = '" + Title + "' " +
                " and n.Website.ID = " + WebsiteID.ToString() + " and n.ParentID = " + ParentID.ToString()).UniqueResult();
            session.Disconnect();

            return nav;
        }

        public CMSDataObject GetTarget()
        {
            return Get(TargetType, TargetID);
        }

        public static IList<Navigation> ListTopLevel(int WebsiteID)
        {
            return Configuration.GetCurrentSession().CreateQuery("select n from Navigation n where n.Website.ID = " + WebsiteID.ToString() + " and n.ParentID = 0").List<Navigation>();
        }
        public static IList<Navigation> ListChildren(int WebsiteID, int ParentID)
        {
            return Configuration.GetCurrentSession().CreateQuery("select n from Navigation n where n.Website.ID = " + WebsiteID.ToString() + " and n.ParentID = " + ParentID.ToString()).List<Navigation>();
        }
        public static IList<Navigation> ListAll(int WebsiteID)
        {
            return Configuration.GetCurrentSession().CreateQuery("select n from Navigation n where n.Website.ID = " + WebsiteID.ToString()).List<Navigation>();
        }

    }
}
